home *** CD-ROM | disk | FTP | other *** search
- /*
- ** Apple Macintosh Developer Technical Support
- **
- ** File: Help.c
- ** Written by: Eric Soldan
- **
- ** Copyright © 1991 Apple Computer, Inc.
- ** All rights reserved.
- */
-
- /* This file contains some sample code for handling dynamic balloon help. The
- ** assumption here, which is valid for DTS.Chat, is that you have controls in
- ** the window content, and these controls need balloon help. Since a DTS.Chat
- ** document window consists of two TextEdit controls, this assumption works quite
- ** well. The code walks the control list, looking at the bounding rect of the
- ** control. If the cursor is within that rect, it shows a belloon with the
- ** associated help text. */
-
-
-
- /*****************************************************************************/
-
-
-
- #include "App.h" /* Get the application includes/typedefs, etc. */
- #include "App.Common.h" /* Get the stuff in common with rez. */
- #include "App.protos.h" /* Get the prototypes for application. */
-
- #ifndef __BALLOONS__
- #include <Balloons.h>
- #endif
-
- #ifndef __PROCESSES__
- #include <Processes.h>
- #endif
-
- #ifndef __UTILITIES__
- #include "Utilities.h"
- #endif
-
-
-
- /*****************************************************************************/
- /*****************************************************************************/
-
-
-
- #pragma segment Main
- void DynamicBalloonHelp(void)
- {
- WindowPtr window, oldPort;
- ProcessSerialNumber cpsn, fpsn;
- FileRecHndl frHndl;
- Point mouseLoc, tip;
- ControlHandle ctl;
- Rect rct;
- short part, message, pos;
- HMMessageRecord helpMessage;
- Boolean procsSame;
- static short lastMessage;
- static short position[4] = {5, 6, 2, 1};
-
- if (gSystemVersion < 0x0700) return;
- /* The system can't support balloons. */
-
- if ((!HMGetBalloons()) || (!IsAppWindow(FrontWindow()))) {
- lastMessage = 0;
- return;
- } /* Balloons have been turned off, or it isn't our window anymore. */
-
- HMGetBalloonWindow(&window);
- if (!window)
- lastMessage = 0;
- /* There is no balloon currently, so there is no last message. */
-
- tip = mouseLoc = GetGlobalMouse();
- part = FindWindow(mouseLoc, &window);
- if ((window != FrontWindow()) || (part != inContent)) {
- lastMessage = 0;
- return;
- } /* We aren't over the content of the front window, so leave. */
-
- GetCurrentProcess(&cpsn);
- GetFrontProcess(&fpsn);
- SameProcess(&cpsn, &fpsn, &procsSame);
- if (!procsSame) {
- lastMessage = 0;
- return;
- } /* We aren't the front process, so leave. */
-
- GetPort(&oldPort);
- frHndl = (FileRecHndl)GetWRefCon(window);
- SetPort(window);
- GlobalToLocal(&mouseLoc);
-
- ctl = ((WindowPeek)window)->controlList;
- while (ctl) {
- rct = (*ctl)->contrlRect;
- if (PtInRect(mouseLoc, &rct)) break;
- ctl = (*ctl)->nextControl;
- } /* Find the control that we are over. */
-
- message = 0;
- if (ctl) {}
-
- if (message) {
-
- if (lastMessage != message) { /* If this balloon isn't current balloon... */
- lastMessage = message;
- helpMessage.hmmHelpType = khmmStringRes;
- helpMessage.u.hmmStringRes.hmmResID = rDynHelpStrings;
- helpMessage.u.hmmStringRes.hmmIndex = message;
- LocalToGlobalRect(&rct);
- pos = (tip.v > (rct.top + rct.bottom) / 2) ? 2 : 0;
- if (tip.h > (rct.left + rct.right) / 2)
- ++pos;
- pos = position[pos];
- SetOrigin(0, 0);
- HMShowBalloon(&helpMessage, tip, &rct, nil, 0, pos, kHMRegularWindow);
- }
- }
- else {
- if (lastMessage)
- HMRemoveBalloon();
- lastMessage = 0;
- }
-
- SetOrigin(0, 0);
- /* It is expected that you will modify this code, so I went ahead and set the origin
- ** back to 0,0, in case your modifications alter it. Currently, I don't change it,
- ** but you might someday. */
-
- SetPort(oldPort);
- }
-